package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import DBFunction.GroupManager;
import DBFunction.UserManager;
import DTO.User;
import Storage.GroupUserList;

/**
 * Servlet implementation class ServerDisplay
 */
public class ServerDisplay extends HttpServlet {
	private static final long serialVersionUID = 1L;
	static Logger logger = Logger.getLogger(ServerDisplay.class);
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServerDisplay() {
        super();
        // TODO Auto-generated constructor stub
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ArrayList<GroupUserList> finalGroupList= new ArrayList();
		try {
			
			
			ArrayList<String> groupList = new ArrayList();
			groupList = GroupManager.getGroupList();
			for(int x=0;x<groupList.size();x++)
			{
				GroupUserList currentGroup = new GroupUserList();
				ArrayList<User> userList = new ArrayList();
				userList = UserManager.getUserListInGroup(groupList.get(x));
				currentGroup.setUserList(userList);
				currentGroup.setGroupName(groupList.get(x));
				finalGroupList.add(currentGroup);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getSession().setAttribute("contextPath", request.getContextPath());
		request.getSession().setAttribute("Group", finalGroupList);
		response.sendRedirect("managementpage.jsp");
	
	  }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
